package cn.ac.jaas.isc.vegetable.quartz.event;

import cn.ac.jaas.isc.vegetable.quartz.config.VegetableQuartzInvokeFactory;
import cn.ac.jaas.isc.vegetable.quartz.service.SysJobLogService;
import cn.ac.jaas.isc.vegetable.quartz.util.TaskInvokeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author 张高昌
 * @date 2022/4/30 16:22
 * @description: 多线程自动配置
 */
@EnableAsync
@Configuration
@ConditionalOnWebApplication
public class EventAutoConfiguration {

    @Autowired
    private TaskInvokeUtil taskInvokeUtil;

    @Autowired
    private SysJobLogService sysJobLogService;

    @Bean
    public SysJobListener sysJobListener() {
        return new SysJobListener(taskInvokeUtil);
    }

    @Bean
    public VegetableQuartzInvokeFactory vegetableQuartzInvokeFactory(ApplicationEventPublisher publisher) {
        return new VegetableQuartzInvokeFactory(publisher);
    }

    @Bean
    public SysJobLogListener sysJobLogListener() {
        return new SysJobLogListener(sysJobLogService);
    }

    @Bean
    public TaskInvokeUtil taskInvokeUtil(ApplicationEventPublisher publisher) {
        return new TaskInvokeUtil(publisher);
    }
}
